var app = getApp();
var https = "https://www.moreclub.cn/";
var pid;
var lat;
var lng;

var getList = function list(that) {
  var uid = wx.getStorageSync('infofrominput');
  wx.request({
    url: https + 'v2/mpackage/open/detail/' + pid + '?uid=' + uid,
    dataType: "json",
    success: function (res) {
      console.log(res.data.data)
      var listdata = res.data;
      if (listdata.success) {
        var list = listdata.data;
        lat = list.lat;
        lng = list.lng;
        var address = list.address;//地址
        var mid = list.merchantId;
        var pid = list.pid;
        var name = list.merchantName;//酒吧名
        var appointmentRemark = list.appointmentRemark;//预约
        var merchantPhone = list.merchantPhone;//电话
        var useRules = list.useRules;//优惠介绍
        var avlStartDate = list.avlStartDate;//开始时间
        var avlEndDate = list.avlEndDate;//结束时间
        var avlTime = list.avlTime//营业时间
        var photos = list.photos;//图片
        var photo = photos.split(";");
        var price = list.price.toFixed(1);//现价
        var oldprice = list.oldPrice.toFixed(1);//原价
        var title = list.title;//标题
        var lat = list.lat;
        var lng = list.lng;
        var uid = list.uid;
        var contents = list.contents;
        for (var n = 0; n < contents.length; n++) {
          var content = contents[n].content;
          console.log(content)
          var cont = content.indexOf(',')
          if (cont >= 0) {
            for (var i = 0; i < content.length; i++) {
              if (content[i] == ',') {
                var cnt = content.split(',');
                console.log(cnt)
                var cnt1 = cnt[0];
                var cnt2 = cnt[1];
                var cnt3 = cnt[2];
                var cnt4 = cnt[3];
                var cnt5 = cnt[4];
                var cnt6 = cnt[5];
                var cnt7 = cnt[6];
                console.log(cnt1)
              }
            }
          } else {
            var cnt0 = content;
          }
        }



        var dots = [];//轮播指示器
        for (var i = 0; i < photo.length; i++) {
          dots.push("");
        }
        dots[0] = 'on';
        that.setData({
          address: address,
          name: name,
          appointmentRemark: appointmentRemark,
          merchantPhone: merchantPhone,
          useRules: useRules,
          avlStartDate: avlStartDate,
          avlEndDate: avlEndDate,
          avlTime: avlTime,
          photos: photos,
          price: price,
          oldprice: oldprice,
          title: title,
          contents: contents,
          content: content,
          photo: photo,
          cont: cont,
          cnt0: cnt0,
          cnt1: cnt1,
          cnt2: cnt2,
          cnt3: cnt3,
          cnt4: cnt4,
          cnt5: cnt5,
          cnt6: cnt6,
          cnt7: cnt7,
          mid: mid,
          pid: pid,
          lat: lat,
          lng: lng,
          uid: uid
        })

      }
    }
  })
}

Page({
  data: {
    indicatorDots: false,
    autoplay: true,
    circular: true,
    interval: 3000,
    duration: 500,
    showView: true
  },

  changeIndicatorDots: function (e) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay: function (e) {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  intervalChange: function (e) {
    this.setData({
      interval: e.detail.value
    })
  },
  durationChange: function (e) {
    this.setData({
      duration: e.detail.value
    })
  },
  swiperChange: function (event) {
    var dots = this.data.photo;
    for (var i = 0; i < dots.length; i++) {
      dots[i] = "";
    }
    dots[event.detail.current] = 'on';
    this.setData({
      dotsclass: dots
    });
  },

  openMap: function (event) {
    wx.openLocation({
      latitude: event.currentTarget.dataset.lat, // 纬度，范围为-90~90，负数表示南纬
      longitude: event.currentTarget.dataset.lng, // 经度，范围为-180~180，负数表示西经
      scale: 28, // 缩放比例          
    })
  },

  colse: function () {
    var that = this;
    that.setData({
      showView: false
    })
  },
  open: function () {
    var that = this;
    that.setData({
      showView: true
    })
  },

  onLoad: function (options) {
    var that = this;
    pid = options.pid;
    try {
      wx.setStorageSync('pid', pid)
    } catch (e) {
    }
    getList(that);

  },
})